<?php

namespace app\admin\model;

use think\facade\Cookie;
use think\facade\Session;
use think\Model;

class User extends Model
{
    /**
     * 检查用户登陆 通过用户名密码
     *
     * @param string $name 用户名
     * @param string $pwd 密码
     * @return void
     */
    public function checkUserinfo($name = '', $pwd = '')
    {
        if (empty($name) || empty($pwd)) {
            return false;
        }
        $userInfo = self::where('username', $name)->find();
        if (!password_verify((string)$pwd, $userInfo['password'])) {
            return false;
        } else {
            return $userInfo;
        }
    }

    /**
     * 获取UUID
     * @return bool|string
     */
    public function getUuid()
    {
        return password_hash(mt_rand(0, 10000), PASSWORD_DEFAULT);
    }

    /**
     * 退出登录
     */
    public static function clearUserinfo(){
        Session::delete('userinfo');
        Session::clear();
        Cookie::delete('userinfo');
    }
}